package com.miage.m1.javabrowser;

// Gere les action que l'on peut faire sur le paneau principal
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.Serializable;
import javax.swing.JPanel;

public class Content extends JPanel implements MouseListener,Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	transient Browser b;
	File entree;
	int i;
	
	public Content (Browser b){
		
		super();
		this.b=b;
		this.setPreferredSize(new Dimension(200,100));
		this.setVisible(true);
	}
	
	public void load(File entree){
		this.entree = entree;
		File[] dirTab = entree.listFiles();
		this.removeAll();
		System.out.println(dirTab.length);
		
		for(i = 0;i<dirTab.length;i++){		
			MyLabel j = new MyLabel(dirTab[i].getName(),dirTab[i].getAbsolutePath());	
			
			j.addMouseListener(this);
			j.setPreferredSize(new Dimension(100,50));
			j.setVisible(true);
			this.add(j);
			
			System.out.println(i + dirTab[i].getName());	
		}
		
		this.repaint();
		this.revalidate();
		
	}
	

	@Override
	public void mouseClicked(MouseEvent e) {
		
		String FlName = ((MyLabel) e.getSource()).getPathName();
		@SuppressWarnings("unused")
		Command c;
		System.out.println("C\'est mon nom : " +FlName);
		File FlFile = new File (FlName);
		
		if(FlFile.isDirectory()){
			System.out.println("coucou");
			load(FlFile);
			
		}
		else{
			c = new Command(FlName, b);
		}
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}


}
